Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): 19315 implement dynamic titles #836

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

vkozio
Copy link
Contributor

@vkozio vkozio commented Sep 13, 2024

https://kontur.fibery.io/Tasks/Task/FE-implement-dynamic-titles-19315

Summary by CodeRabbit

  • New Features

    • Introduced localization for new modes: "Cookies" and "Report."
    • Enhanced document title updates based on current route changes for better navigation context.
  • Bug Fixes

    • Improved fallback logic for route resolution, enhancing performance and clarity.
  • Refactor

    • Updated route titles to support dynamic translations, improving internationalization.
  • Chores

    • Removed the useTabNameUpdate hook, streamlining title management in the application.

Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on enhancing localization, updating routing logic, and managing document titles. New entries for "cookies" and "report" are added to the localization file. The routing logic is refined for better clarity and performance, while the document title is dynamically updated based on the current route. Additionally, a custom hook for updating the tab name is removed, indicating a shift in how tab names are managed within the application.

Changes

File Change Summary
src/core/localization/translations/en/common.json Added keys for "cookies" and "report" to enhance localization.
src/core/router/atoms/currentRoute.ts Improved logic for determining the current route, separating matching and fallback logic for clarity and performance.
src/core/router/components/Router.tsx Added a listener to update the document title based on the current route, improving user experience.
src/core/router/routes.tsx Modified route titles to use dynamic translations instead of static strings, enhancing internationalization capabilities.
src/core/router/types.ts Changed the title property type in the AppRoute interface from `string
src/utils/hooks/useTabNameUpdate.tsx Removed the useTabNameUpdate hook, which was responsible for updating the document title based on a provided name.
src/views/CommonView.tsx Removed invocation of the useTabNameUpdate hook, indicating a change in how the tab name is managed within the component.

Poem

In the garden where changes bloom,
Cookies and reports find their room.
Titles dance with routes so bright,
A rabbit hops with pure delight.
With each update, we leap and cheer,
For a smoother path, we hold so dear! 🐇✨

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 4eb40d7 and 9635d68.

Files selected for processing (7)
  • src/core/localization/translations/en/common.json (1 hunks)
  • src/core/router/atoms/currentRoute.ts (1 hunks)
  • src/core/router/components/Router.tsx (1 hunks)
  • src/core/router/routes.tsx (2 hunks)
  • src/core/router/types.ts (1 hunks)
  • src/utils/hooks/useTabNameUpdate.tsx (0 hunks)
  • src/views/CommonView.tsx (0 hunks)
Files not reviewed due to no reviewable changes (2)
  • src/utils/hooks/useTabNameUpdate.tsx
  • src/views/CommonView.tsx
Additional comments not posted (9)
src/core/router/types.ts (1)

9-9: Verify the impact of the title property type change.

The change to restrict the title property to only accept string values is a good simplification. However, it's important to ensure that this change doesn't break any existing code that may have relied on the ability to use JSX elements for dynamic or styled titles.

Please run the following script to identify any instances in the codebase where the title property is being assigned a JSX element:

If the script yields any results, those instances will need to be updated to comply with the new string type constraint.

Do you want me to open a GitHub issue to track the task of updating any affected code?

Verification successful

No JSX usage found in title property, change appears safe

Our verification process did not find any instances where the title property is being assigned a JSX element or using React.createElement. This suggests that the change from string | JSX.Element to string for the title property in the AppRoute interface is unlikely to cause issues in the existing codebase.

As an extra precaution, it may be worthwhile to:

  • Conduct a quick manual review of any components that use the AppRoute interface.
  • Test the application thoroughly to ensure no unexpected behavior occurs due to this change.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for potential usage of JSX elements in the `title` property.

# Test: Search for JSX element usage in the `title` property. Expect: No results.
rg --type typescript $'<[A-Z][a-zA-Z]*(\s+[a-zA-Z]+="[^"]+")*\s*/?>.*title:\s*\{' -g '!src/core/router/types.ts'

Length of output: 148


Script:

#!/bin/bash
# Description: Search for potential usage of JSX elements or React.createElement in the `title` property

# Find TypeScript files and search for JSX-like syntax in the title property
fd -e ts -e tsx | xargs rg -i 'title:\s*<'

# Find TypeScript files and search for React.createElement usage in the title property
fd -e ts -e tsx | xargs rg -i 'title:\s*React\.createElement'

# Find TypeScript files and search for any object assignment to the title property
fd -e ts -e tsx | xargs rg -i 'title:\s*\{'

Length of output: 154

src/core/router/atoms/currentRoute.ts (3)

19-20: LGTM!

The normalization of the current location is correctly implemented and is necessary for matching the current location with the available routes.


21-25: LGTM!

The code segment correctly searches for a matching route using the normalized location. The matchPath function from the react-router library is used correctly to match the route path with the normalized location. The exact option is set to true to ensure that the route path matches the normalized location exactly.


26-32: LGTM!

The code segment correctly returns the matched route if found. If no match is found, it falls back to a route identified by the defaultRoute property in the routesConfig. This change improves clarity and maintainability by separating the matching logic from the fallback logic, making it easier to understand the flow of route resolution. The fallback mechanism is now more explicit, relying on the defaultRoute rather than searching through all routes again, which could enhance performance by reducing unnecessary iterations.

src/core/router/components/Router.tsx (1)

32-35: LGTM!

The code segment correctly updates the document title based on the current route, improving the user experience by displaying relevant information about the current page in the browser tab. The implementation is well-structured and follows best practices.

src/core/router/routes.tsx (2)

52-52: LGTM!

The change to use i18n.t for translating the route title is a good practice for internationalization. The implementation looks correct.


115-115: LGTM!

Similar to the previous change, using i18n.t for translating the route title is a good practice for internationalization. The implementation looks correct.

src/core/localization/translations/en/common.json (2)

368-368: LGTM!

The addition of the cookies entry in the modes section is consistent with the provided summary and is unlikely to cause any issues.


370-370: LGTM!

The addition of the report entry in the modes section is consistent with the provided summary and is likely to enhance the user experience by providing a singular form for reports.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vkozio vkozio requested a review from a team September 13, 2024 11:02
Copy link

Language To Recheck Fuzzy Untranslated Total
ar 3 24 101 128
de 2 24 101 127
es 3 24 101 128
id 2 24 101 127
ko 3 24 101 128
uk 0 7 8 15

Copy link

Bundle size diff

Old size New size Diff
5.23 MB 5.23 MB 82 B (0.00%)

@vkozio vkozio merged commit 251dc19 into main Sep 18, 2024
9 checks passed
@vkozio vkozio deleted the 19315-fe-implement-dynamic-titles branch September 18, 2024 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants